import '../public.dart';

/// 网络图片加载
class EmptyComponent extends StatelessWidget {
  final Image image;
  final String imageAsset;
  final Text text;
  final String desc;
  final List<Widget> widgets;
  final BoxConstraints constraints;

  EmptyComponent(
      {Key key,
      this.image,
      this.imageAsset,
      this.text,
      this.desc,
      this.widgets = const [],
      this.constraints = const BoxConstraints(minHeight: 200)})
      : super(key: key);

  List<Widget> _setWidgets() {
    List<Widget> list = [];
    String _image = imageAsset ?? 'assets/images/empty_wumingxi.png';
    String _desc = desc ?? '暂无明细';

    list.add(image ?? Image.asset(_image));
    list.add(text ??
        Text(_desc,
            style: TextStyle(color: ColorUtil.rgba(255, 255, 255, 0.25))));
    if (widgets.length > 0) {
      list.addAll(widgets);
    }
    return list;
  }

  Widget build(BuildContext context) {
    return ConstrainedBox(
        constraints: constraints,
        child: Container(
            alignment: Alignment.center,
            child: Column(
                mainAxisAlignment: MainAxisAlignment.center,
                children: _setWidgets())));
  }
}
